package com.xyhuo.leetcode;

import com.xyhuo.leetcode.common.ListNode;

import java.util.ArrayList;
import java.util.List;

public class ReverseList {
    public ListNode reverseList(ListNode head) {
        if (null == head) {
            return null;
        }
        List<ListNode> list = new ArrayList<>();
        ListNode node = head;
        while (node != null) {
            list.add(node);
            node = node.next;
        }
        for (int i = list.size() - 1; i > 0; i--) {
            list.get(i).next = list.get(i - 1);
        }
        list.get(0).next = null;
        return list.get(list.size() - 1);
    }
}
